package com.ruoyi.web.controller.system;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.system.domain.DiseaseCategory;
import com.ruoyi.system.service.IDiseaseCategoryService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.Arrays;
import java.util.List;

/**
 * 疾病分类Controller
 *
 * @author ruoyi
 * @date 2023-07-04
 */
@Api(tags = "疾病分类模块")
@RestController
@RequestMapping("/system/DiseaseCategory")
public class DiseaseCategoryController extends BaseController {
    @Autowired
    private IDiseaseCategoryService diseaseCategoryService;

    /**
     * 查询疾病分类列表
     */
    @ApiOperation(value = "查询疾病分类列表")
    @PreAuthorize("@ss.hasPermi('system:DiseaseCategory:list')")
    @GetMapping("/list")
    public Page<DiseaseCategory> list(DiseaseCategory entity, Page<DiseaseCategory> page) {

        LambdaQueryWrapper<DiseaseCategory> lambdaQueryWrapper = new LambdaQueryWrapper<DiseaseCategory>();
        return diseaseCategoryService.page(page, lambdaQueryWrapper);
    }

    /**
     * 导出疾病分类列表
     */
    @ApiOperation(value = "导出疾病分类列表")
    @PreAuthorize("@ss.hasPermi('system:DiseaseCategory:export')")
    @Log(title = "疾病分类", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, DiseaseCategory diseaseCategory) {
        LambdaQueryWrapper<DiseaseCategory> queryWrapper = new LambdaQueryWrapper<>();
        List<DiseaseCategory> list = diseaseCategoryService.list(queryWrapper);
        ExcelUtil<DiseaseCategory> util = new ExcelUtil<DiseaseCategory>(DiseaseCategory.class);
        util.exportExcel(response, list, "疾病分类数据");
    }


    /**
     * 获取疾病分类详细信息
     */
    @ApiOperation(value = "获取疾病分类详细信息")
    @PreAuthorize("@ss.hasPermi('system:DiseaseCategory:query')")
    @GetMapping(value = "/{Id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(diseaseCategoryService.getById(id));
    }

    /**
     * 新增疾病分类
     */
    @ApiOperation(value = "新增疾病分类")
    @PreAuthorize("@ss.hasPermi('system:DiseaseCategory:add')")
    @Log(title = "疾病分类", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody DiseaseCategory diseaseCategory) {
        return toAjax(diseaseCategoryService.save(diseaseCategory));
    }

    /**
     * 修改疾病分类
     */
    @ApiOperation(value = "修改疾病分类")
    @PreAuthorize("@ss.hasPermi('system:DiseaseCategory:edit')")
    @Log(title = "疾病分类", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody DiseaseCategory diseaseCategory) {
        return toAjax(diseaseCategoryService.updateById(diseaseCategory));
    }


    /**
     * 删除疾病分类
     */
    @ApiOperation(value = "删除疾病分类")
    @PreAuthorize("@ss.hasPermi('system:DiseaseCategory:remove')")
    @Log(title = "疾病分类", businessType = BusinessType.DELETE)
    @DeleteMapping("/{Ids}")
    public AjaxResult remove(@PathVariable Long[] Ids) {
        return toAjax(diseaseCategoryService.removeBatchByIds(Arrays.asList(Ids)));
    }
}
